package castledefense.game.render;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import castledefense.data.GameData;
import castledefense.data.Resources;
import castledefense.game.render.effects.LightningHandler;
import castledefense.game.render.effects.MissileHandler;
import castledefense.logic.Map;
import castledefense.logic.missile.Missile;

public class RenderMissile {

	public static final LightningHandler lightningHandler = new LightningHandler();

	final private MissileHandler fireHandler = new MissileHandler(GameData.fire);
	final private MissileHandler waterHandler = new MissileHandler(
			GameData.water);

	public void render(SpriteBatch batch, float delta,
			ArrayList<Missile> missiles) {

		for (Missile tmp : missiles) {
			batch.draw(Resources.missileIm, (float) (Map.cellWidth*tmp.x), (float) (Map.cellWidth*tmp.y));
		}

		batch.end();
		lightningHandler.render();
		batch.begin();
		fireHandler.render(batch, delta);
		waterHandler.render(batch, delta);
	}

	public void update(int delta) {
		lightningHandler.update(delta);
		fireHandler.update(delta);
		waterHandler.update(delta);
	}

	public void addBlast(float x, float y, int type) {
		if (type == GameData.fire) {
			fireHandler.addBlast(x, y);
		} else if (type == GameData.water) {
			waterHandler.addBlast(x, y);
		}
	}

	public final void create(float x1, float y1, float x2, float y2) {
		lightningHandler.create(x1, y1, x2, y2);
	}

}
